<?php
/**
 * Created by PhpStorm.
 * User: Admin
 * Date: 2018/7/23
 * Time: 18:11
 */
namespace app\index\controller;

use fast\BaiduNlp;
use think\Controller;

class Test extends Controller
{

    public function test3()
    {
        /*$nlp=new BaiduNlp();
        $title='个人名片设计';
        $content='<p>个人名片设计，个人名片设计个人名片设计，个人名片设计，个人名片设计个人名片设计个人名片设计个人名片设计，个人名片设计</p>
<p><audio style="display: none;" controls="controls"></audio></p>';
        dump($nlp->auto_cate($title,$content));

        */
        $nlp=new BaiduNlp();
        $data=db('work')->select();
        foreach ($data as $k=>$v){
            $title=$v['title'];
            $content=$v['content'];
            $res=$nlp->auto_cate($title,$content);
            dump($res);
            $res=$res['item'];
            if (!empty($res['lv1_tag_list'])){
                foreach ($res['lv1_tag_list'] as $n){
                    db('work_cate')->insertGetId([
                        'pid'=>$v['id'],
                        'level'=>1,
                        'tag'=>$n['tag'],
                        'score'=>$n['score']
                    ]);
                }
            }
            if (!empty($res['lv2_tag_list'])){
                foreach ($res['lv2_tag_list'] as $n){
                    db('work_cate')->insertGetId([
                        'pid'=>$v['id'],
                        'level'=>2,
                        'tag'=>$n['tag'],
                        'score'=>$n['score']
                    ]);
                }
            }
            dump(db('')->getLastSql());
        }
    }
}